<?php
require_once(LIB_PATH."view/header.inc.php");

$allFields = $modelObj->field();
$foreignFields = $modelObj->foreignField();
$searchFields = $modelObj->searchField();
$statusFields = $modelObj->statusField();
?>
<style>
    .table td {
        border: 1px solid #ddd;
        padding: 8px;
        vertical-align: middle;
    }
<?php
$statusColor = $modelObj->statusColor();
foreach($statusColor as $key=>$color){
    echo '.currentStatus'.$key.' {
    color: '.$color.' ; font-weight:bold;
}
';
}
?>
</style>
<div class="panel admin-panel">
  <div class="panel-head" style="
    height: 60px;
">
      <div style="float:left;position:relative;
      "><a href="templower,edit,<?php echo $modelObj->key(); ?>,0" class="button border-main">新 增</a></div>
  <?php
  if(property_exists($modelObj->className(),'status') && preg_match("/88::|88：：/",$allFields['status'][2])) {
      ?>
      <div style="float:left; margin-left:20px;position:relative; "><a href="templower,list,status,<?php echo STATUS_ADMIN_DELETE;?>" class="button border-main" style="<?php if(r('status')==STATUS_ADMIN_DELETE)echo 'color:red';?>">回收站</a></div>
      <?php
  }
  ?>
      <div style="float:right;position:relative"><a href="#" onclick="window.location.href=window.location.href" class="button border-main">刷 新</a></div>
      <div style="margin-top: 10px;position:relative;width:100%;float:left">
<?php
if(SQL_ADMIN) {
    ?>
    <form method="get" style="margin-top:8px;
    width:100%;position:relative;float:left;
">
        <?php


        echo "SQL&nbsp;<input type='text' value=\"" . htmlspecialchars($sql) . "\" name='sql' style='width:300px' />&nbsp;&nbsp;&nbsp;";
        ?><input type="submit" value="SQL搜索"/>
    </form>
    <br/>
    <?php
}
?>
          <form method="get" style="
    width: 100%;position:relative;float:left;margin-top:8px;
">
              <?php
              if(!empty($searchFields)>=1){


              foreach($searchFields as $name=>$info){
                  $type = $info[0];
                  $reg = "/(.*?)@/i";
                  preg_match($reg,$info[1],$matches);
                  $desc = $matches[1];

                  if(array_key_exists($name,$modelObj->statusField())){
                      echo "$desc&nbsp;<input type='hidden' value='".r($name)."' name=".$name." id=".$name."  />&nbsp;&nbsp;&nbsp;";
                  }else if(array_key_exists($name,$modelObj->foreignField())){
                      echo "$desc&nbsp;<input type='hidden' value='".r($name)."' name=".$name." id=".$name."  />&nbsp;&nbsp;&nbsp;";
                  }else{
                      echo "$desc&nbsp;<input type='text' value='".r($name)."' name=".$name."  id=".$name." />&nbsp;&nbsp;&nbsp;";
                  }

              } ?>
                  <input type="submit" value="搜索" />
              <?php
              }
              ?>
          </form>

      </div>

  </div>
<table class="table table-hover text-center">
<tr>
TempTh
</tr>
<?php
for($i = 0; $i < count($currentList); $i++) {//优先显示操作列
    ?>
<?php if(r_int('currentKey')==$currentList[$i][$modelObj->key()]){
    echo "<tr style=\"background-color:lightgray\" >";
}else{
    echo "<tr>";
}?>
TempTd
<?php
    echo "</tr>";
}//end for
?>
</table>
  <?php
  $pagerObj->show();
  ?>
</div>


<script>
function  changeStatus(id,fieldName,val,btn,reason){
         $.ajax({    // 填充地址
             type : 'get',
             url  : '/templower,saveJson',
             data:"<?php echo $modelObj->key(); ?>="+id+"&"+fieldName+"="+val+"&reason="+reason,
             dataType : 'json',
        })
        .fail(function (xhr,status,errorTrown){
            console.log('11122');
        })
        .done(function(backData,textStatus,obj){
            console.log('填充地址',textStatus);
            console.log(btn);
            $("#"+fieldName+"__"+id).html(btn);
            $("#"+fieldName+"__"+id).removeClass();
            $("#"+fieldName+"__"+id).addClass("currentStatus"+val);
            //alert(btn);
            //window.location.href = window.location.href;
        });
}


<?php
$allStatus = $modelObj->statusField();
foreach($allStatus as $f=> $values){//begin main foreach
    $options = "";
    foreach($values as $v=> $info){
       if(r($f)!=="" && r($f) == $v){
            $options .= "<option selected value=\'{$v}\'>{$info[0]}</option>";
        }else{
            $options .= "<option  value=\'{$v}\'>{$info[0]}</option>";
        }
    }//end sub foreach
    $fun .=  "function change{$f}(t){
    $('#{$f}').val(t);
}\r\n";
$sel .= "$('#{$f}').after('<select class=\'mtop10\' onchange=\'change{$f}(this.options[this.options.selectedIndex].value)\' id=\'{$f}_helper\'><option value=\'\'>请选择</option>{$options}</select>');\r\n";
$sel .= "
//var current{$f} = $('#{$f}').val();
//$(\"#{$f}_helper\").find(\"option[text='\"+current{$f}+\"']\").attr(\"selected\",true);

";
}//end main foreach
echo $fun;
 ?>

<?php
$allStatus = $modelObj->foreignField();
foreach($allStatus as $f=> $tableName){//begin main foreach
    $className = mymodel::getClassName($tableName);
    if(!$className) continue;
    $obj = new $className();
    $sql = "SELECT * FROM ".$tableName.' LIMIT 100 ';
    $allRows = $obj->query($sql);

    $options = "";
    foreach($allRows as $row){
        $keys = array_keys($row);
        $key0 = $keys[0];
        $key1 = $keys[1];
        $v = $row[$key0];
        $descF = $row[$key1]."($v)";
       if(r($f)!=="" && r($f) == $v){
            $options .= "<option selected value=\'{$v}\'>{$descF}</option>";
        }else{
            $options .= "<option  value=\'{$v}\'>{$descF}</option>";
        }
    }//end sub foreach
    $fun .=  "function change{$f}(t){
    $('#{$f}').val(t);
}\r\n";
$sel .= "$('#{$f}').after('<select class=\'mtop10\' onchange=\'change{$f}(this.options[this.options.selectedIndex].value)\' id=\'{$f}_helper\'><option value=\'\'>请选择</option>{$options}</select>');\r\n";
$sel .= "
//var current{$f} = $('#{$f}').val();
//$(\"#{$f}_helper\").find(\"option[text='\"+current{$f}+\"']\").attr(\"selected\",true);

";
}//end main foreach
echo $fun;
 ?>


$(document).ready(function(){
    <?php
    echo $sel;
    ?>
});
</script>
<?php
require_once(LIB_PATH."view/footer.inc.php");
?>
    
      
      
      
      
